package com.example.testgit.mapstruct;

import com.example.testgit.VO.StudentBasicVO;
import com.example.testgit.entity.StudentDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.util.List;
@Mapper
public interface StudentBasicConverter {

    StudentBasicConverter INSTANCE = Mappers.getMapper(StudentBasicConverter.class);

    @Mappings({
            @Mapping(source = "sex", target = "sex", qualifiedByName = "sexTrans"),
            @Mapping(source = "eduType", target = "eduType", qualifiedByName = "eduTypeTrans"),
            @Mapping(source = "marriage", target = "marriage", qualifiedByName = "marrTrans"),
            @Mapping(source = "politicalAffiliation", target = "politicalAffiliation", qualifiedByName = "poliTrans"),
            @Mapping(source = "sourceType", target = "sourceType", qualifiedByName = "sourceTrans"),
            @Mapping(source = "schoolStatus", target = "schoolStatus", qualifiedByName = "statusTrans"),
            @Mapping(source = "birthday", target = "birthday", dateFormat = "yyyy-MM-dd"),
            @Mapping(source = "registerTime", target = "registerTime", dateFormat = "yyyy-MM-dd"),
            @Mapping(source = "graduationTime", target = "graduationTime", dateFormat = "yyyy-MM-dd")
    })
    StudentBasicVO toVO(StudentDO studentDO);

    @Mappings({
            @Mapping(source = "sex", target = "sex", qualifiedByName = "sexTrans"),
            @Mapping(source = "eduType", target = "eduType", qualifiedByName = "eduTypeTrans"),
            @Mapping(source = "marriage", target = "marriage", qualifiedByName = "marrTrans"),
            @Mapping(source = "politicalAffiliation", target = "politicalAffiliation", qualifiedByName = "poliTrans"),
            @Mapping(source = "sourceType", target = "sourceType", qualifiedByName = "sourceTrans"),
            @Mapping(source = "schoolStatus", target = "schoolStatus", qualifiedByName = "statusTrans"),
            @Mapping(source = "birthday", target = "birthday", dateFormat = "yyyy-MM-dd"),
            @Mapping(source = "registerTime", target = "registerTime", dateFormat = "yyyy-MM-dd"),
            @Mapping(source = "graduationTime", target = "graduationTime", dateFormat = "yyyy-MM-dd")
    })
    List<StudentBasicVO> toVOList(List<StudentDO> studentDOList);

    @Named("sexTrans")
    default String sexTrans(Integer sex) {
        return sex.equals(0) ? "男" : "女";
    }

    @Named("eduTypeTrans")
    default String eduTypeTrans(Integer eduType) {
        if (eduType.equals(1)) return "本科生";
        else if (eduType.equals(2)) return "二学位";
        else if (eduType.equals(3)) return "硕士";
        else return "博士";
    }

    @Named("marrTrans")
    default String marrTrans(Integer marriage) {
        return marriage.equals(0) ? "未婚" : "已婚";
    }

    @Named("poliTrans")
    default String poliTrans(Integer politicalAffiliation) {
        if (politicalAffiliation.equals(0)) return "共青团员";
        else if (politicalAffiliation.equals(1)) return "预备党员";
        else if (politicalAffiliation.equals(2)) return "党员";
        else return "群众";
    }

    @Named("sourceTrans")
    default String sourceTrans(Integer sourceType) {
        if (sourceType.equals(0)) return "非定向";
        else if (sourceType.equals(1)) return "定向";
        else if (sourceType.equals(2)) return "留学生";
        else return "在职生";
    }

    @Named("statusTrans")
    default String statusTrans(Integer schoolStatus) {
        if (schoolStatus.equals(0)) return "注册学籍";
        else if (schoolStatus.equals(1)) return "已离校";
        else return "保留学籍";
    }
}
